package com.zx.kitchen.index.common.mvp.presenter;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zx.kitchen.index.common.entity.GoodsDayDetailsBean;
import com.zx.kitchen.index.common.mvp.OnResultListener;
import com.zx.kitchen.index.common.mvp.model.BusinessGoodsDayDetailModelImpl;
import com.zx.kitchen.index.common.mvp.view.GoodsDayDetailView;

/**
 * Created by Administrator on 2017/3/21.
 */

public class BusinessGoodsDayDetailPresenter implements OnResultListener {
    private BusinessGoodsDayDetailModelImpl businessGoodsDayDetailModel;
    private GoodsDayDetailView goodsDayDetailView;
    private Context mContext;

    public BusinessGoodsDayDetailPresenter(Context mContext, GoodsDayDetailView goodsDayDetailView) {
        this.mContext = mContext;
        this.goodsDayDetailView = goodsDayDetailView;
        businessGoodsDayDetailModel = new BusinessGoodsDayDetailModelImpl();
    }

    public void getFromNet(String goods_id, String day) {
        businessGoodsDayDetailModel.getFromNet(0, mContext, goods_id, day, this, null);
    }

    @Override
    public void onSuccess(int requestCode, String str) {
        GoodsDayDetailsBean goodsDayDetailsBean = JSON.parseObject(str, new TypeReference<GoodsDayDetailsBean>() {
        });
        goodsDayDetailView.onSuccess(goodsDayDetailsBean);
    }

    @Override
    public void onFailure(int requestCode, String str) {
        goodsDayDetailView.onFail(str);
    }
}
